package com.bweab.controll.depositcontroll;

import com.bweab.service.api.DepositTbServiceInterface;
import com.bweab.service.impl.DepositTbServiceInterfaceImpl;
import com.bweab.util.JSONResult;
import com.bweab.util.JSONStats;
import com.bweab.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/alterDepositInfo")
public class AlterDepositInfo extends HttpServlet {
    //创建服务对象
    DepositTbServiceInterface depositTbService =new DepositTbServiceInterfaceImpl();
    //创建返回结果
    JSONResult jsonResult =new JSONResult();


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取信息
        int dormitoryId = Integer.parseInt(req.getParameter("dormitoryId"));
        //获取用户id
        int userId= Integer.parseInt(req.getParameter("userId"));


        int userFee= Integer.parseInt(req.getParameter("userFee"));
        int depositId= Integer.parseInt(req.getParameter("depositId"));
        //调用dao
        int rows= depositTbService.alterDepositInfo(dormitoryId,userId,userFee,depositId);

        //如果影响的结果大于0则修改成功否则修改失败
        if (rows > 0) {

            jsonResult.setStatusCode(JSONStats.ALTER_DEPOSIT_SUCCESS.getStatusCode());
            jsonResult.setMessage(JSONStats.ALTER_DEPOSIT_SUCCESS.getMessage());
        }else {
            jsonResult.setStatusCode(JSONStats.ALTER_DEPOSIT_ERROR.getStatusCode());
            jsonResult.setMessage(JSONStats.ALTER_DEPOSIT_ERROR.getMessage());
        }

        WebUtil.writeJson(resp,jsonResult);


    }
}
